<template>
    <view>
        <view class="loadinggif" v-if="isloading">
            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/loading.gif"></image>
        </view>
        <block v-if="!isloading">
            <view class="page">
                <view class="formmain">
                    <view class="formbd">
                        <view class="flex-row sjname flex-y-center">
                            <image :src="url + store.logo"></image>
                            <view class="flex-grow-1">
                                {{ store.name }}
                            </view>
                            <view class="tableinfo">
                                <view>{{ type_name }}({{ table_name }})</view>
                                <view>您所在位置</view>
                            </view>
                        </view>
                        <view class="cart-item flex-row flex-y-center" v-for="(item, index) in cart_list" :key="index">
                            <view class="flex-grow-0 flex-y-center">
                                <image class="goods-pic" mode="aspectFill" :src="item.logo"></image>
                            </view>

                            <view class="flex-grow-1 flex-col">
                                <view class="flex-grow-1">
                                    <view class="goods-name">{{ item.name }}</view>
                                    <view class="attr-list">
                                        <view class="attr-item">{{ item.spec }}</view>
                                    </view>
                                </view>
                                <view class="flex-grow-0 flex-row">
                                    <view class="flex-grow-1 num">×{{ item.num }}</view>
                                    <view class="flex-grow-0 price">￥{{ item.money }}</view>
                                </view>
                            </view>
                        </view>
                        <view class="formftyh">
                            <view class="formbdyh flex-row flex-y-center" v-if="reduction.length > 0">
                                <view class="flex-row flex-y-center flex-grow-1">
                                    <view class="yhhead jian">减</view>
                                    <view>在线支付满减</view>
                                </view>
                                <view class="flex-grow-0" v-if="isnewuser == '2'">-￥{{ mjmoney }}</view>
                                <view class="flex-grow-0" style="color: #999" v-if="isnewuser == '1'">新用户不享有此优惠</view>
                            </view>
                            <view class="formbdyh flex-row flex-y-center" v-if="storeset.xyh_open == '1' && isnewuser == '1'">
                                <view class="flex-row flex-y-center flex-grow-1">
                                    <view class="yhhead xin">新</view>
                                    <view>新客户下单立减</view>
                                </view>
                                <view class="flex-grow-0">-￥{{ storeset.xyh_money }}</view>
                            </view>
                            <view class="weui-cells weui-cells_after-title" style="border-top: 1rpx solid #f4f4f4">
                                <navigator @tap="showcart" class="weui-cell weui-cell_access" hoverClass="weui-cell_active">
                                    <view class="weui-cell__hd">
                                        <image
                                            mode="aspectFit"
                                            src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/personal/youhuiquan.png"
                                            style="margin-right: 15rpx; vertical-align: middle; width: 40rpx; height: 40rpx"
                                        ></image>
                                    </view>
                                    <view class="weui-cell__bd">商家优惠券</view>
                                    <view class="weui-cell__ft weui-cell__ft_in-access" v-if="Coupons.length == 0">暂无此商家优惠券</view>
                                    <view class="weui-cell__ft_in-access" v-if="Coupons.length > 0 && yhqkdje == 0">选择优惠券</view>
                                    <view class="weui-cell__ft_in-access" v-if="Coupons.length > 0 && yhqkdje != 0">-￥{{ yhqkdje }}</view>
                                </navigator>
                            </view>
                            <view class="weui-cells weui-cells_after-title" style="border-top: 1rpx solid #f4f4f4">
                                <navigator @tap="hbshowcart" class="weui-cell weui-cell_access" hoverClass="weui-cell_active">
                                    <view class="weui-cell__hd">
                                        <image
                                            mode="aspectFit"
                                            src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/hb.png"
                                            style="margin-right: 15rpx; vertical-align: middle; width: 40rpx; height: 40rpx"
                                        ></image>
                                    </view>
                                    <view class="weui-cell__bd">红包</view>
                                    <view class="weui-cell__ft weui-cell__ft_in-access" v-if="hbarr.length == 0">暂无红包</view>
                                    <view class="weui-cell__ft_in-access" v-if="hbarr.length > 0 && hbkdje == 0">选择红包</view>
                                    <view class="weui-cell__ft_in-access" v-if="hbarr.length > 0 && hbkdje != 0">-￥{{ hbkdje }}</view>
                                </navigator>
                            </view>
                            <view class="sfk flex-row flex-y-center">
                                <view class="sfk-fv flex-grow-0">实付款</view>
                                <view class="flex-grow-1 xiaoji">
                                    <view>已优惠￥{{ totalyh }}</view>
                                    <view>小计</view>
                                    <view>￥{{ totalPrice }}</view>
                                </view>
                            </view>
                        </view>
                        <view class="formft">
                            <view class="weui-cells weui-cells_after-title">
                                <picker @change="bindcjPickerChange" :range="cjarray" :value="cjindex">
                                    <view class="weui-cell weui-cell_access" hoverClass="weui-cell_active">
                                        <view class="weui-cell__bd">{{ storeset.cj_name }}</view>
                                        <view class="weui-cell__ft weui-cell__ft_in-access">{{ cjarray[cjindex] }}</view>
                                    </view>
                                </picker>
                                <navigator class="weui-cell weui-cell_access" hoverClass="weui-cell_active" style="border-bottom: 1rpx solid #efeff4" url="../takeout/note">
                                    <view class="weui-cell__bd" style="min-width: 120rpx">备注</view>
                                    <view class="weui-cell__ft weui-cell__ft_in-access">{{ note }}</view>
                                </navigator>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="footmj" v-if="reduction.length > 0 && mjindex != null && isnewuser == '2'">
                下单已满{{ reduction[mjindex].full }}元，可减
                <text>{{ reduction[mjindex].reduction }}</text>
                元
            </view>
            <view class="dbtjdd flex-row flex-y-center">
                <view class="dbtjddl flex-row flex-y-center">
                    <view class="flex-grow-0">已优惠￥{{ totalyh }}</view>
                    <view class="flex-grow-1">
                        合计
                        <text>￥{{ totalPrice }}</text>
                    </view>
                </view>
                <view class="dbtjddr">
                    <form @reset="formReset" @submit="tjddformSubmit" :reportSubmit="true">
                        <button formType="submit" :style="'background:' + color">提交订单</button>
                    </form>
                </view>
            </view>
            <view class="modalzz" v-if="!mdoaltoggle"></view>
            <view :class="'modal ' + (mdoaltoggle ? '' : 'active')">
                <view class="modalbd">
                    <icon size="50" type="success"></icon>
                    <view class="xdcg">下单成功!</view>
                </view>
            </view>
            <!-- parse <template is="xytemp" :data="fwxy:fwxy,xymc:xymc,xynr:xynr"></template> -->
            <block name="xytemp">
                <view class="zhezhao" v-if="!fwxy"></view>
                <view :class="'kcrzxy ' + (fwxy ? '' : 'active')">
                    <view class="kcrzxyhd">{{ xymc }}</view>
                    <scroll-view scrollY class="kcrzxybd" style="height: 600rpx">
                        <rich-text :nodes="xynr"></rich-text>
                    </scroll-view>
                    <view @tap="queren" class="queren">确定</view>
                </view>
            </block>
            <form @reset="formReset" @submit="formSubmit" :reportSubmit="true">
                <view @tap="yczz" class="drawer_screen" v-if="showModal"></view>
                <view class="drawer_box" v-if="showModal">
                    <view class="drawer_title">请选择支付方式</view>
                    <view class="weui-cells weui-cells_after-title">
                        <radio-group @change="radioChange1" class="radio-group" name="radiogroup">
                            <label v-if="wxzf">
                                <view class="weui-cell">
                                    <view class="zfimg">
                                        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/weixin.png"></image>
                                    </view>
                                    <view class="weui-cell__bd">微信支付</view>
                                    <view class="weui-cell__ft">
                                        <radio :checked="zffs == 1" value="wxzf"></radio>
                                    </view>
                                </view>
                            </label>
                            <label v-if="kqyue">
                                <view class="weui-cell" style="border-top: 1rpx solid #e6e6e6">
                                    <view class="zfimg">
                                        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/yeqb.png"></image>
                                    </view>
                                    <view class="weui-cell__bd">
                                        余额支付
                                        <text class="yetext">您的余额 {{ userInfo.wallet }}</text>
                                    </view>
                                    <view class="weui-cell__ft">
                                        <radio :checked="zffs == 2" color="#FF9700" :disabled="!kqyue" value="yezf"></radio>
                                    </view>
                                </view>
                            </label>
                            <label v-if="chzf">
                                <view class="weui-cell" style="border-top: 1rpx solid #e6e6e6">
                                    <view class="zfimg">
                                        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/wmtime.png" style="height: 50rpx"></image>
                                    </view>
                                    <view class="weui-cell__bd">
                                        餐后支付
                                        <text class="yetext" style="color: #999"></text>
                                    </view>
                                    <view class="weui-cell__ft">
                                        <radio :checked="zffs == 4" color="#34aaff" :disabled="!chzf" value="chzf"></radio>
                                    </view>
                                </view>
                            </label>
                        </radio-group>
                    </view>
                    <view class="drawer_title1">
                        您选择的{{ zfwz }}
                        <text v-if="zffs == 3">({{ jf_proportion }}积分可抵1元)</text>
                    </view>
                    <button :class="btntype" :disabled="zfz" formType="submit">
                        <view v-if="!zfz && zffs != 4">
                            确定支付
                            <text class="zftext">￥{{ totalPrice }}</text>
                        </view>
                        <view v-if="!zfz && zffs == 4">
                            餐后支付
                            <text class="zftext">￥{{ totalPrice }}</text>
                        </view>
                        <view v-if="zfz">
                            <text class="zfztext">支付中...</text>
                        </view>
                    </button>
                </view>
            </form>
        </block>
        <view @tap.stop.prevent="closecart" :class="'share-modal ' + (share_modal_active ? 'active' : '')">
            <view class="share-modal-body">
                <view class="yhqhead">选择优惠券</view>
                <radio-group @change="radioChangeFun" class="radio-group" name="radiogroup">
                    <scroll-view scrollY style="height: 400rpx">
                        <label
                            @tap.stop.prevent="xzq"
                            :data-full="item.full"
                            :data-kdje="item.reduce"
                            :data-rdid="item.id"
                            data-type="代金券"
                            v-for="(item, index) in Coupons"
                            :key="index"
                        >
                            <view class="mdlist">
                                <view class="coupon-item unreceive" :id="item.coupon_id">
                                    <view class="item-left" style="background: #f65c5c">
                                        <text class="num">{{ item.reduce }}</text>
                                        <text class="unit">元</text>
                                    </view>
                                    <view class="item-right">
                                        <text class="name">{{ item.name }}</text>
                                        <text class="conditions" v-if="item.full != '0.0'">满{{ item.full }}可用</text>
                                        <text class="conditions" v-else>无门槛</text>
                                        <text class="prefer">有效期至{{ item.end_time }}</text>
                                    </view>
                                </view>
                                <view class="radio">
                                    <radio :checked="activeradio == item.id" :color="color" :disabled="gwcinfo.money < item.full" :value="item.id"></radio>
                                </view>
                            </view>
                        </label>
                        <view class="kong" v-if="Coupons.length == 0">
                            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/wushuju.png"></image>
                            <view>暂无此门店的优惠券</view>
                        </view>
                    </scroll-view>
                </radio-group>
            </view>
        </view>
        <view @tap.stop.prevent="hbclosecart" :class="'share-modal ' + (hbshare_modal_active ? 'active' : '')">
            <view class="share-modal-body">
                <view class="yhqhead">选择红包</view>
                <radio-group @change="hbradioChangeFun" class="radio-group" name="hbradiogroup">
                    <scroll-view scrollY style="height: 400rpx">
                        <label
                            @tap.stop.prevent="xzhb"
                            :data-full="item.full"
                            :data-kdje="item.reduce"
                            :data-rdid="item.id"
                            data-type="红包"
                            v-for="(item, index) in hbarr"
                            :key="index"
                        >
                            <view class="mdlist">
                                <view class="coupon-item unreceive" :id="item.coupon_id">
                                    <view class="item-left" style="background: #f65c5c">
                                        <text class="num">{{ item.reduce }}</text>
                                        <text class="unit">元</text>
                                    </view>
                                    <view class="item-right">
                                        <text class="name">{{ item.name }}</text>
                                        <text class="conditions" v-if="item.full != '0.0'">满{{ item.full }}可用</text>
                                        <text class="conditions" v-else>无门槛</text>
                                        <text class="prefer">有效期至{{ item.end_time }}</text>
                                    </view>
                                </view>
                                <view class="radio">
                                    <radio :checked="hbactiveradio == item.id" :color="color" :disabled="gwcinfo.money < item.full" :value="item.id"></radio>
                                </view>
                            </view>
                        </label>
                        <view class="kong" v-if="hbarr.length == 0">
                            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/wushuju.png"></image>
                            <view>暂无可用红包</view>
                        </view>
                    </scroll-view>
                </radio-group>
            </view>
        </view>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var qqmapsdk;
var app = getApp();
var util = require('../../utils/util.js');
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            share_modal_active: false,
            activeradio: '',
            hbshare_modal_active: false,
            hbactiveradio: '',
            isloading: true,
            navbar: ['外卖配送', '到店用餐'],
            fwxy: true,
            xymc: '到店用餐服务协议',
            xynr: '',
            selectedindex: 0,
            color: '#019fff',
            checked: false,
            cart_list: [],
            wmindex: 0,
            wmtimearray: ['尽快送达'],
            cjindex: 0,
            cjarray: ['1份', '2份', '3份', '4份', '5份', '6份', '7份', '8份', '9份', '10份', '10份以上'],
            mdoaltoggle: true,
            total: 0,
            showModal: false,
            zfz: false,
            zfwz: '',
            btntype: 'btn_ok1',
            yhqkdje: 0,
            hbkdje: 0,
            tableid: '',
            drid: '',

            userInfo: {
                wallet: ''
            },

            type_name: '',
            table_name: '',
            Coupons: '',
            hbarr: '',
            CouponSet: '',
            chzf: false,
            wxzf: false,
            kqyue: false,
            psfarr: '',
            reduction: '',

            store: {
                logo: '',
                name: ''
            },

            storeset: {
                xyh_open: '',
                xyh_money: '',
                cj_name: ''
            },

            sjstart: '',
            xyhmoney: '',
            isnewuser: '',

            gwcinfo: {
                money: 0
            },

            gwcprice: '',
            note: '',
            psf: 0,
            zffs: 0,
            name: '',
            mobile: '',
            form_id2: '',
            date: '',
            timestart: '',
            time: '',
            radioChange: '',
            hbradioChange: '',
            totalyh: '',
            totalPrice: '',
            mjindex: '',
            mjmoney: '',
            url: '',
            jf_proportion: ''
        };
    },
    onLoad: function (t) {
        app.globalData.setNavigationBarColor(this);
        console.log(t);
        this.setData({
            tableid: t.tableid,
            drid: t.drid
        });
        var i;
        var that = this;
        var n = t.storeid;
        var d = uni.getStorageSync('users').id;
        if (null != t.drid) {
            i = 'mycar2';
        }
        if (null == t.drid) {
            i = 'mycar';
        }
        console.log(i);
        uni.removeStorageSync('note');
        app.globalData.util.request({
            url: 'entry/wxapp/UserInfo',
            cachetime: '0',
            data: {
                user_id: d
            },
            success: function (t) {
                console.log(t);
                that.setData({
                    userInfo: t.data
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/Zhuohao',
            cachetime: '0',
            data: {
                id: t.tableid
            },
            success: function (t) {
                console.log(t);
                that.setData({
                    type_name: t.data.type_name,
                    table_name: t.data.table_name
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/MyCoupons',
            cachetime: '0',
            data: {
                store_id: n,
                user_id: d
            },
            success: function (t) {
                console.log(t.data);
                for (var a = [], e = [], o = 0; o < t.data.length; o++) {
                    if ('1' != t.data[o].coupon_type && '1' == t.data[o].type) {
                        a.push(t.data[o]);
                    }
                    if ('1' != t.data[o].coupon_type && '2' == t.data[o].type) {
                        e.push(t.data[o]);
                    }
                }
                console.log(a, e);
                that.setData({
                    Coupons: a,
                    hbarr: e
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/CouponSet',
            cachetime: '0',
            success: function (t) {
                console.log(t.data);
                that.setData({
                    CouponSet: t.data
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/StoreInfo',
            cachetime: '0',
            data: {
                store_id: n,
                type: 1
            },
            success: function (t) {
                console.log(t.data);
                var a = t.data;
                var e = t.data.store.coordinates.split(',');
                var o = {
                    lng: Number(e[1]),
                    lat: Number(e[0])
                };
                console.log(o);
                if ('2' == a.storeset.is_zt) {
                    that.setData({
                        navbar: ['外卖配送']
                    });
                }
                if ('1' == a.storeset.is_chzf) {
                    that.setData({
                        chzf: true
                    });
                }
                if ('1' == a.storeset.is_wxzf) {
                    that.setData({
                        wxzf: true
                    });
                }
                if ('1' == getApp().globalData.xtxx.is_yuepay && '1' == a.storeset.is_yuepay) {
                    that.setData({
                        kqyue: true
                    });
                }
                that.setData({
                    psfarr: t.data.psf,
                    reduction: t.data.reduction,
                    store: t.data.store,
                    storeset: t.data.storeset,
                    sjstart: o,
                    xynr: t.data.storeset.ztxy
                });
                app.globalData.util.request({
                    url: 'entry/wxapp/' + i,
                    cachetime: '0',
                    data: {
                        store_id: n,
                        user_id: d,
                        type: 2
                    },
                    success: function (t) {
                        console.log(t);
                        app.globalData.util.request({
                            url: 'entry/wxapp/IsNew',
                            data: {
                                store_id: n,
                                user_id: d
                            },
                            cachetime: '0',
                            success: function (t) {
                                console.log(t.data);
                                if ('1' == a.storeset.xyh_open && 1 == t.data) {
                                    that.setData({
                                        xyhmoney: a.storeset.xyh_money,
                                        isnewuser: '1'
                                    });
                                } else {
                                    that.setData({
                                        xyhmoney: 0,
                                        isnewuser: '2'
                                    });
                                }
                                that.countMj();
                            }
                        });
                        that.setData({
                            cart_list: t.data.res,
                            gwcinfo: t.data,
                            gwcprice: t.data.money
                        });
                    }
                });
            }
        });
    },
    onReady: function () {},
    onShow: function () {
        var t = uni.getStorageSync('note');
        console.log(t);
        this.setData({
            note: t
        });
    },
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    methods: {
        showcart: function () {
            this.setData({
                share_modal_active: !this.share_modal_active
            });
        },

        closecart: function () {
            this.setData({
                share_modal_active: false
            });
        },

        hbshowcart: function () {
            this.setData({
                hbshare_modal_active: !this.hbshare_modal_active
            });
        },

        hbclosecart: function () {
            this.setData({
                hbshare_modal_active: false
            });
        },

        openxy: function () {
            this.setData({
                fwxy: false
            });
        },

        queren: function () {
            this.setData({
                fwxy: true
            });
        },

        bindPickerChange: function (t) {
            console.log('picker发送选择改变，携带值为', t.detail.value);
            this.setData({
                wmindex: t.detail.value
            });
        },

        bindcjPickerChange: function (t) {
            console.log('picker发送选择改变，携带值为', t.detail.value);
            this.setData({
                cjindex: t.detail.value
            });
        },

        selectednavbar: function (t) {
            console.log(t);
            this.setData({
                selectedindex: t.currentTarget.dataset.index
            });
            var a = this.psfbf;
            console.log(a);
            if (1 == t.currentTarget.dataset.index) {
                this.setData({
                    psf: 0
                });
            } else {
                this.setData({
                    psf: a
                });
            }
            this.gettotalprice();
        },

        checkboxChange: function (t) {
            this.setData({
                checked: !this.checked
            });
        },

        radioChange1: function (t) {
            console.log('radio1发生change事件，携带value值为：', t.detail.value);
            if ('wxzf' == t.detail.value) {
                this.setData({
                    zffs: 1,
                    zfwz: '微信支付',
                    btntype: 'btn_ok1'
                });
            }
            if ('yezf' == t.detail.value) {
                this.setData({
                    zffs: 2,
                    zfwz: '余额支付',
                    btntype: 'btn_ok2'
                });
            }
            if ('jfzf' == t.detail.value) {
                this.setData({
                    zffs: 3,
                    zfwz: '积分支付',
                    btntype: 'btn_ok3'
                });
            }
            if ('chzf' == t.detail.value) {
                this.setData({
                    zffs: 4,
                    zfwz: '餐后支付',
                    btntype: 'btn_ok4'
                });
            }
        },

        KeyName: function (t) {
            this.setData({
                name: t.detail.value
            });
        },

        KeyMobile: function (t) {
            this.setData({
                mobile: t.detail.value
            });
        },

        tjddformSubmit: function (t) {
            console.log(t);
            this.setData({
                form_id2: t.detail.formId
            });
            this.setData({
                showModal: true
            });
        },

        yczz: function () {
            this.setData({
                showModal: false
            });
        },

        mdoalclose: function () {
            this.setData({
                mdoaltoggle: true
            });
        },

        bindDateChange: function (t) {
            console.log('date 发生 change 事件，携带值为', t.detail.value, this.datestart);
            this.setData({
                date: t.detail.value
            });
            if (t.detail.value == this.datestart) {
                console.log('日期没有修改');
                this.setData({
                    timestart: util.formatTime(new Date()).substring(11, 16)
                });
            } else {
                console.log('修改了日期');
                this.setData({
                    timestart: '00:01'
                });
            }
        },

        bindTimeChange: function (t) {
            console.log('time 发生 change 事件，携带值为', t.detail.value);
            this.setData({
                time: t.detail.value
            });
        },

        radioChangeFun: function (t) {
            this.setData({
                radioChange: t.detail.value
            });
            console.log('radio发生change事件，携带value值为：', t.detail.value);
        },

        hbradioChangeFun: function (t) {
            this.setData({
                hbradioChange: t.detail.value
            });
            console.log('radio发生change事件，携带value值为：', t.detail.value);
        },

        xzq: function (t) {
            console.log(t.currentTarget.dataset, this.gwcinfo.money, this.CouponSet.yhq_set);
            if (Number(t.currentTarget.dataset.full) > this.gwcinfo.money) {
                uni.showModal({
                    title: '提示',
                    content: '您的消费金额不满足此优惠券条件'
                });
                return false;
            }
            if ('1' == this.CouponSet.yhq_set) {
                this.setData({
                    share_modal_active: false,
                    activeradio: t.currentTarget.dataset.rdid,
                    yhqkdje: t.currentTarget.dataset.kdje
                });
            } else {
                this.setData({
                    share_modal_active: false,
                    activeradio: t.currentTarget.dataset.rdid,
                    yhqkdje: t.currentTarget.dataset.kdje,
                    hbactiveradio: '',
                    hbkdje: 0
                });
            }
            this.gettotalprice();
        },

        xzhb: function (t) {
            console.log(t.currentTarget.dataset, this.gwcinfo.money, this.CouponSet.yhq_set);
            if (Number(t.currentTarget.dataset.full) > this.gwcinfo.money) {
                uni.showModal({
                    title: '提示',
                    content: '您的消费金额不满足此红包条件'
                });
                return false;
            }
            if ('1' == this.CouponSet.yhq_set) {
                this.setData({
                    hbshare_modal_active: false,
                    hbactiveradio: t.currentTarget.dataset.rdid,
                    hbkdje: t.currentTarget.dataset.kdje
                });
            } else {
                uni.showModal({
                    title: '提示',
                    content: '优惠券与红包不可同时享用'
                });
                this.setData({
                    hbshare_modal_active: false,
                    hbactiveradio: t.currentTarget.dataset.rdid,
                    hbkdje: t.currentTarget.dataset.kdje,
                    activeradio: '',
                    yhqkdje: 0
                });
            }
            this.gettotalprice();
        },

        gettotalprice: function () {
            var t = this.gwcprice;
            var a = this.mjmoney;
            var e = this.xyhmoney;
            var o = this.yhqkdje;
            var i = this.hbkdje;
            var s = (Number(a) + Number(e) + Number(o) + Number(i)).toFixed(2);
            var n = (Number(t) - s).toFixed(2);
            if (n < 0) {
                n = 0;
            }
            console.log('gwcprice', t, 'mjmoney', a, 'xyhmoney', e, 'totalyh', s, 'totalPrice', n, 'yhqkdje', o, 'hbkdje', i);
            this.setData({
                totalyh: s,
                totalPrice: n,
                isloading: false
            });
        },

        jsmj: function (t, a) {
            for (var e, o = 0; o < a.length; o++) {
                if (Number(t) >= Number(a[o].full)) {
                    e = o;
                    break;
                }
            }
            return e;
        },

        countMj: function () {
            var t = this.gwcprice;
            var a = this.reduction.reverse();
            var e = this.jsmj(t, a);
            var o = this.isnewuser;
            console.log(t, a, e, o);
            var i = 0;
            if (0 < a.length && null != e && '2' == o) {
                i = a[e].reduction;
            }
            this.setData({
                reduction: a,
                mjindex: e,
                mjmoney: i
            });
            this.gettotalprice();
        },

        formSubmit: function (e) {
            var t = this.zffs;
            console.log(e, t);
            if (null == t) {
                uni.showModal({
                    title: '提示',
                    content: '请选择支付方式'
                });
                return false;
            }
            var o = [];
            this.cart_list.map(function (t) {
                if (0 < t.num) {
                    var a = {};
                    a.name = t.name;
                    a.img = t.logo;
                    a.num = t.num;
                    a.money = t.money;
                    a.dishes_id = t.good_id;
                    a.spec = t.spec;
                    o.push(a);
                }
            });
            console.log(o);
            var that = this;
            var s = getApp().globalData.getOpenId;
            console.log('form发生了submit事件，携带数据为：', e.detail.value.radiogroup, this.activeradio, this.hbactiveradio);
            var a = this.tableid;
            var n = e.detail.formId;
            var d = this.form_id2;
            var r = uni.getStorageSync('users').id;
            var l = this.store.id;
            var c = this.totalPrice;
            var u = this.totalyh;
            var h = this.gwcinfo.box_money;
            var g = this.mjmoney;
            var p = this.xyhmoney;
            var f = parseInt(this.selectedindex) + 1;
            var m = this.note;
            var y = this.cjarray[this.cjindex];
            var w = this.yhqkdje;
            var v = this.activeradio;
            var x = this.hbactiveradio;
            var _ = this.hbkdje;
            console.log(
                '桌子id',
                a,
                s,
                n,
                d,
                r,
                l,
                '实付',
                c,
                '总优惠',
                u,
                '包装费',
                h,
                '满减金额',
                g,
                '新用户money',
                p,
                '优惠券',
                w,
                '红包',
                _,
                '订单类型',
                f,
                '留言',
                m,
                'sz',
                o,
                '餐具数量',
                y
            );
            if ('yezf' == e.detail.value.radiogroup) {
                var b = Number(this.userInfo.wallet);
                var D = Number(c);
                console.log(b, D);
                if (b < D) {
                    return void uni.showToast({
                        title: '余额不足支付',
                        icon: 'loading'
                    });
                }
            }
            if ('yezf' == e.detail.value.radiogroup) {
                var z = 2;
            }
            if ('wxzf' == e.detail.value.radiogroup) {
                z = 1;
            }
            if ('jfzf' == e.detail.value.radiogroup) {
                z = 3;
            }
            if ('chzf' == e.detail.value.radiogroup) {
                z = 5;
            }
            console.log('支付方式', z);
            if ('' == n) {
                uni.showToast({
                    title: '没有获取到formid',
                    icon: 'loading',
                    duration: 1000
                });
            } else {
                this.setData({
                    zfz: true
                });
                app.globalData.util.request({
                    url: 'entry/wxapp/AddDnOrder',
                    cachetime: '0',
                    data: {
                        table_id: a,
                        user_id: r,
                        store_id: l,
                        money: c,
                        discount: u,
                        mj_money: g,
                        xyh_money: p,
                        note: m,
                        type: 2,
                        form_id: n,
                        form_id2: d,
                        pay_type: z,
                        sz: o,
                        tableware: y,
                        yhq_money: w,
                        yhq_money2: _,
                        coupon_id: v,
                        coupon_id2: x
                    },
                    success: function (t) {
                        console.log(t);
                        var a = t.data;
                        that.setData({
                            zfz: false,
                            showModal: false
                        });
                        if ('yezf' == e.detail.value.radiogroup) {
                            console.log('余额支付流程');
                            if ('已开台' == a) {
                                uni.showModal({
                                    title: '提示',
                                    content: '对不起，此桌已开台'
                                });
                            } else {
                                if ('下单失败' != a) {
                                    that.setData({
                                        mdoaltoggle: false
                                    });
                                    setTimeout(function () {
                                        uni.reLaunch({
                                            url: '../wddd/order?status=4'
                                        });
                                    }, 1000);
                                    if (null != that.drid) {
                                        console.log(that.drid);
                                        app.globalData.util.request({
                                            url: 'entry/wxapp/WcDrShop',
                                            cachetime: '0',
                                            data: {
                                                id: that.drid
                                            },
                                            success: function (t) {
                                                console.log(t);
                                            }
                                        });
                                    }
                                } else {
                                    uni.showToast({
                                        title: '支付失败',
                                        icon: 'loading'
                                    });
                                }
                            }
                        }
                        if ('chzf' == e.detail.value.radiogroup) {
                            console.log('餐后支付流程');
                            if ('已开台' == a) {
                                uni.showModal({
                                    title: '提示',
                                    content: '对不起，此桌已开台'
                                });
                            } else {
                                if ('下单失败' != a) {
                                    that.setData({
                                        mdoaltoggle: false
                                    });
                                    setTimeout(function () {
                                        uni.reLaunch({
                                            url: '../wddd/order'
                                        });
                                    }, 1000);
                                    if (null != that.drid) {
                                        console.log(that.drid);
                                        app.globalData.util.request({
                                            url: 'entry/wxapp/WcDrShop',
                                            cachetime: '0',
                                            data: {
                                                id: that.drid
                                            },
                                            success: function (t) {
                                                console.log(t);
                                            }
                                        });
                                    }
                                } else {
                                    uni.showToast({
                                        title: '支付失败',
                                        icon: 'loading'
                                    });
                                }
                            }
                        }
                        if ('wxzf' == e.detail.value.radiogroup) {
                            console.log('微信支付流程');
                            if (0 == c) {
                                uni.showModal({
                                    title: '提示',
                                    content: '0元买单请选择其他方式支付'
                                });
                                that.setData({
                                    zfz: false
                                });
                            } else {
                                if ('已开台' == a) {
                                    uni.showModal({
                                        title: '提示',
                                        content: '对不起，此桌已开台'
                                    });
                                } else {
                                    if ('下单失败' != a) {
                                        app.globalData.util.request({
                                            url: 'entry/wxapp/pay',
                                            cachetime: '0',
                                            data: {
                                                openid: s,
                                                money: c,
                                                order_id: a
                                            },
                                            success: function (t) {
                                                console.log(t);
                                                if (null != that.drid) {
                                                    console.log(that.drid);
                                                    app.globalData.util.request({
                                                        url: 'entry/wxapp/WcDrShop',
                                                        cachetime: '0',
                                                        data: {
                                                            id: that.drid
                                                        },
                                                        success: function (t) {
                                                            console.log(t);
                                                        }
                                                    });
                                                }
                                                uni.requestPayment({
                                                    timeStamp: t.data.timeStamp,
                                                    nonceStr: t.data.nonceStr,
                                                    package: t.data.package,
                                                    signType: t.data.signType,
                                                    paySign: t.data.paySign,
                                                    success: function (t) {
                                                        console.log(t.data);
                                                        console.log(t);
                                                        console.log(n);
                                                    },
                                                    complete: function (t) {
                                                        console.log(t);
                                                        if ('requestPayment:fail cancel' == t.errMsg) {
                                                            uni.showToast({
                                                                title: '取消支付',
                                                                icon: 'loading',
                                                                duration: 1000
                                                            });
                                                            setTimeout(function () {
                                                                uni.reLaunch({
                                                                    url: '../wddd/order'
                                                                });
                                                            }, 1000);
                                                        }
                                                        if ('requestPayment:ok' == t.errMsg) {
                                                            that.setData({
                                                                mdoaltoggle: false
                                                            });
                                                            setTimeout(function () {
                                                                uni.reLaunch({
                                                                    url: '../wddd/order?status=4'
                                                                });
                                                            }, 1000);
                                                        }
                                                    }
                                                });
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }
                });
            }
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        }
    }
};
</script>
<style>
@import './smdcform.css';
</style>
